package LeetCode;

import java.util.Arrays;

public class LC_324_WiggleSortII {

    public static void main(String[] args) {

    }

    static class Solution {
        public static void wiggleSort(int[] nums) {
            int len = nums.length;
            int[] newnums = new int[len];
            int i, j, tmp;
            Arrays.sort(nums);
            for (i = 0; i < (len - 1) / 2 + 1; i++) {
                tmp = nums[i];
                nums[i] = nums[len - 1 - i];
                nums[len - 1 - i] = tmp;
            }
            i = 0;
            while (2 * i + 1 < len) {
                newnums[2 * i + 1] = nums[i];
                i++;
            }
            j = i;
            while (j < len && 2 * (j - i) < len) {
                newnums[2 * (j - i)] = nums[j];
                j++;
            }
            for (i = 0; i < nums.length; i++) nums[i] = newnums[i];
        }

    }
}